import {
  daysList,
  addTask,
  taskInfo,
  startTask,
  updateTask,
  uploadTask,
  deleteTask,
  process,
} from '@/api/Days'

export default defineStore('useDays', {
  state: () => ({}),
  getters: {},
  actions: {
    //日常任务列表
    async getDaysList(params) {
      let url = $globalRequestUrl({
        url: daysList,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    //添加任务
    async taskSave(params) {
      let url = $globalRequestUrl({
        url: addTask,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    //获取任务信息
    async taskInfo(id) {
      let url = $globalRequestUrl({
        url: taskInfo + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },
    //启动任务检查
    async taskStart(id) {
      let url = $globalRequestUrl({
        url: startTask + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },
    //修改任务
    async taskUpdate(params) {
      let url = $globalRequestUrl({
        url: updateTask,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'PUT' })
        return rep
      } catch (error) {
        return error
      }
    },

    //提交任务检查
    async uploadTask(params) {
      let url = $globalRequestUrl({
        url: uploadTask,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //删除任务检查
    async deleteTask(id) {
      let url = $globalRequestUrl({
        url: deleteTask + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'DELETE' })
        return rep
      } catch (error) {
        return error
      }
    },

    //处理任务
    async process(type, params) {
      let url = $globalRequestUrl({
        url: process + `/${type}`,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
  },
})
